package com.my.stock.core;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class TimelineUtil {

	private List<Double> dataList = new ArrayList<Double>();

	private int icount = 0;

	public void insertData(Double d) {
		totalCount = totalCount + d;
		dataList.add(d);
		insertOneMin(d);
		insertThreeMins(d);
		insertFiveMins(d);
		insertTenMins(d);
		icount++;
	}

	private void insertOneMin(Double d) {

		int oneMinLines = 119;

		if (oneMinsData.size() <= oneMinLines) {
			oneMinsData.addLast(d);
			oneMinsCount = oneMinsCount + d;
		} else {
			oneMinsData.addLast(d);
			oneMinsCount = oneMinsCount + d;
			Double first = oneMinsData.removeFirst();
			oneMinsCount = oneMinsCount - first;
		}
	}

	private void insertThreeMins(Double d) {

		int oneMinLines = 359;

		if (threeMinsData.size() <= oneMinLines) {
			threeMinsData.addLast(d);
			threeMinsCount = threeMinsCount + d;
		} else {
			threeMinsData.addLast(d);
			threeMinsCount = threeMinsCount + d;
			Double first = threeMinsData.removeFirst();
			threeMinsCount = threeMinsCount - first;
		}
	}

	private void insertFiveMins(Double d) {

		int oneMinLines = 599;

		if (fiveMinsData.size() <= oneMinLines) {
			fiveMinsData.addLast(d);
			fiveMinsCount = fiveMinsCount + d;
		} else {
			fiveMinsData.addLast(d);
			fiveMinsCount = fiveMinsCount + d;
			Double first = fiveMinsData.removeFirst();
			fiveMinsCount = fiveMinsCount - first;
		}
	}

	private void insertTenMins(Double d) {

		int oneMinLines = 1199;

		if (TenMinsData.size() <= oneMinLines) {
			TenMinsData.addLast(d);
			TenMinsCount = TenMinsCount + d;
		} else {
			TenMinsData.addLast(d);
			TenMinsCount = TenMinsCount + d;
			Double first = TenMinsData.removeFirst();
			TenMinsCount = TenMinsCount - first;
		}
	}

	private double oneMinsCount = 0d;
	private double threeMinsCount = 0d;
	private double fiveMinsCount = 0d;
	private double TenMinsCount = 0d;
	private double totalCount = 0d;

	private LinkedList<Double> oneMinsData = new LinkedList<Double>();
	private LinkedList<Double> threeMinsData = new LinkedList<Double>();
	private LinkedList<Double> fiveMinsData = new LinkedList<Double>();
	private LinkedList<Double> TenMinsData = new LinkedList<Double>();

	public double get1SecData() {
		Double count = 0d;
		int total = dataList.size();
		for (int i = total - 1; i >= total - 1; i--) {
			count = count + dataList.get(i);
		}
		return count;
	}

	public static void main(String args[]) {

		TimelineUtil tu = new TimelineUtil();

		for (Double i = 0d; i < 2000; i++) {
			tu.insertData(1d);
//			System.out.println(tu.getOneMinsCount());
//			System.out.println(tu.getThreeMinsCount());
//			System.out.println(tu.getFiveMinsCount());
			System.out.println(tu.getTenMinsCount());
		}

	}

	public double getOneMinsCount() {
		return oneMinsCount;
	}

	public double getThreeMinsCount() {
		return threeMinsCount;
	}

	public double getFiveMinsCount() {
		return fiveMinsCount;
	}

	public double getTenMinsCount() {
		return TenMinsCount;
	}

	public double getOneMinsSize() {
		return oneMinsData.size();
	}

	public double getThreeMinsSize() {
		return threeMinsData.size();
	}

	public double getFiveMinsSize() {
		return fiveMinsData.size();
	}

	public double getTenMinsSize() {
		return TenMinsData.size();
	}

	public double getTotalListSize() {
		return dataList.size();
	}
	
	public double getTotalCount() {
		return totalCount;
	}


}
